package cn.ctodb.mall.goods.config;

import cn.ctodb.mall.goods.freemarker.macro.CategoryDirective;
import freemarker.template.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import javax.annotation.PostConstruct;

@org.springframework.context.annotation.Configuration
public class FreemarkerConfiguration {

    @Autowired
    protected Configuration configuration;

    @Autowired
    protected CategoryDirective categoryDirective;

    @Bean
    public DefaultObjectWrapper defaultObjectWrapper() {
        return new DefaultObjectWrapperBuilder(Configuration.getVersion()).build();
    }

    @PostConstruct
    public void setSharedVariable() throws TemplateModelException {
        configuration.setSharedVariable("category", categoryDirective);
    }

}
